package cn.tianyigps.tianyigpsapiv2.dao;

import cn.tianyigps.tianyigpsapiv2.oauth2.context.ClientPrincipal;
import cn.tianyigps.tianyigpspublic.bean.EquipmentConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2019/4/26_17:27
 */
@Repository
public class EquipmentConfigDao extends BaseDao<EquipmentConfig>{

    @Autowired
    private MongoTemplate mongoTemplate;

    public EquipmentConfig findByEquipmentId(String equipmentId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("equipmentId").is(equipmentId));
        if(!admin()){
            query.addCriteria(Criteria.where("clientId").is(ClientPrincipal.getClientId()));
        }
        return mongoTemplate.findOne(query,EquipmentConfig.class);
    }
}
